// pages/zhanghu/shouhuodz/xinzengdz/xinzengdz.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      region: ["", "", ""],
      showAdd:true,
      province:"",
      city:"",
      district:"",
      detail:"",
      phone:"",
      defaultFlag:"",
      i:"",
      addId:"",
      value:""
  },
  formSubmit: function (e) {
    console.log(e)
    wx.request({
      url: 'http://123.206.228.246:50080/wxone/address/add',
      method: 'POST',
      data: {
        userId: app.globalData.userId,
        name: e.detail.value.name,
        province: e.detail.value.province,
        city: e.detail.value.city,
        district: e.detail.value.district,
        detail: e.detail.value.detail,
        phone: e.detail.value.phone,
        defaultFlag: e.detail.value.defaultFlag
      },
     
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: (res) => {
        console.log(res)
        console.log("添加地址成功")
        console.log()
        wx.showToast({
          title: '添加地址成功',
          icon: 'success',
          duration: 1000,
          mask: true,
          success: function (res) {
            wx.navigateBack({
              delta: 1
            })
          },
          fail: function (res) { },
          complete: function (res) { },
        })

      }
    })
  },
  
  formSubmis: function (e) {
    wx.request({
      url: 'http://123.206.228.246:50080/wxone/address/updateAddr',
      method: 'POST',
      data: {
        addrID: app.address.addrId,
        userId: app.globalData.userId,
        name: e.detail.value.name,
        province: e.detail.value.province,
        city: e.detail.value.city,
        district: e.detail.value.district,
        detail: e.detail.value.detail,
        phone: e.detail.value.phone,
        defaultFlag: e.detail.value.defaultFlag
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: (res) => {
        console.log(res)
        console.log("修改地址成功")
        wx.showToast({
          title: '修改地址成功',
          icon: 'success',
          duration: 1000,
          mask: true,
          success: function (res) {
            wx.navigateBack({
              delta: 1
            })
          },
          fail: function (res) { },
          complete: function (res) { },
        })

      }
    })
  },
  showAdd: function () {
    this.setData({
      showAdd: false
    })
  },
  changeRegin(e) {
    this.setData({
      region: e.detail.value,
      showAdd: true
    });
    console.log(e.detail.value)
  },
  bind: function (e) {
    console.log(e.detail.value)
    this.setData({
      defaultFlag: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(app.address.addrId)
    console.log(options)
    this.setData({
      i: options.i,
      addId: app.globalData.userId
    })
  }, 
})